package Test.ThreadTest;

import km.org.apache.poi.hssf.usermodel.HSSFSheet;
import km.org.apache.poi.hssf.usermodel.HSSFWorkbook;
import km.org.apache.poi.ss.usermodel.Cell;
import km.org.apache.poi.ss.usermodel.DateUtil;
import km.org.apache.poi.ss.usermodel.Row;

import java.io.File;
import java.io.FileInputStream;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-04-29
 * @Description: ${description}
 * @ModifyLog:
 **/

public class ReadExcel {

    public static void readExce() throws Exception{
        File excelFile = new File("/Users/mike/table5.xls");
        HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(excelFile));
        HSSFSheet sheet = wb.getSheetAt(0);

        for(Row row :sheet)
        {
            for (Cell cell : row) {
                switch (cell.getCellType()) {
                    case Cell.CELL_TYPE_STRING://字符串
                        System.out.print(cell.getRichStringCellValue().getString());
                        System.out.print("|");
                        break;
                    case Cell.CELL_TYPE_NUMERIC://数值与日期
                        if (DateUtil.isCellDateFormatted(cell)) {
                            System.out.print(String.valueOf(cell.getDateCellValue()));
                        } else {
                            System.out.print(cell.getNumericCellValue());
                        }
                        System.out.print("|");
                        break;
                    case Cell.CELL_TYPE_BOOLEAN://boolean类型
                        System.out.print(cell.getBooleanCellValue());
                        System.out.print("|");
                        break;
                    default:
                }
            }
            System.out.println();
        }
    }
}
